using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AVGManager : MonoBehaviour {
	
	TextAsset Script;
	bool stopUpdate;
	EventManager eventManager;
	Queue<ScriptInterpreter.ScriptComannd> Comannds;
	ComanndType nowRun;
	
	// 子物件.
	public GameObject TextBox;
	public GameObject LD;
	public GameObject CD;
	public GameObject RD;
	
	// Use this for initialization
	void Start () {
		
	}
	
	public void RunScript(EventManager obj,TextAsset script){
		Script = script;
		eventManager = obj;
		Comannds = ScriptInterpreter.Interpreter(script);
	}
	
	// Update is called once per frame
	void Update () {
		if(!stopUpdate && Script != null)
		{
			if(nowRun == 0)
			{
				if(Comannds.Count == 0)
				{
					eventManager.RuningNextEvent();
					stopUpdate = true;
				}
				else 
				{
					var Comannd = Comannds.Dequeue();
					switch(Comannd.comanndType)
					{
					case ComanndType.txtbox:
						ShowTextBox();
						break;
					case ComanndType.ld:
						if(Comannd.Position == Vector2.zero)
						ShowLd(Comannd.Name);
						nowRun = ComanndType.ld;
						break;
					}
				}
			}
		}
	}
	
	void ShowTextBox(){
		TextBox.transform.FindChild("BackGround").gameObject.active = true;
	}
	
	void ShowLd(string Name)
	{
		
	}
}
